package com.ycfmedical.bed.ui.fragment;

import android.annotation.SuppressLint;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.ycfmedical.bed.Constants;
import com.ycfmedical.bed.R;
import com.ycfmedical.bed.local.entity.StaffInfo;
import com.ycfmedical.bed.present.StaffPresenter;
import com.ycfmedical.bed.utils.ChineseToSpell;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import cn.droidlover.xdroidmvp.mvp.XLazyFragment;

/**
 * Created by Administrator on 2017/3/1.
 */
@SuppressLint("ValidFragment")
public class BaseStaffFragment extends XLazyFragment<StaffPresenter> {
    
    @BindView(R.id.staff_image)
    ImageView staffImage;
    @BindView(R.id.staff_name)
    TextView staffName;
    @BindView(R.id.pinYin)
    TextView pinYin;
    @BindView(R.id.staff_position)
    TextView staffPosition;
    @BindView(R.id.staffExp)
    TextView staffExp;
    @BindView(R.id.staff_sex)
    TextView staffSex;
    @BindView(R.id.staffSexValue)
    TextView staffSexValue;
    @BindView(R.id.staff_phone)
    TextView staffPhone;
    @BindView(R.id.staffPhoneValue)
    TextView staffPhoneValue;
    @BindView(R.id.staff_brief)
    TextView staffBrief;

    private Long id;//员工ID；
    private int type;//员工类型；

    public BaseStaffFragment() {}

    @Override
    public void initData(Bundle savedInstanceState) {
        //设置字体
        //Typeface typeface = Typeface.createFromAsset(getContext().getAssets(), "zhongqizhi.TTF");
        //  staffName.setTypeface(typeface);

        getP().loadData(id, type);
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_staff_info;
    }

    @Override
    public StaffPresenter newP() {
        return new StaffPresenter();
    }


    public void showData(StaffInfo staffInfo) {
        Log.i("staff", "showData: " + staffInfo.getStaffId() + staffInfo.getStaffName());
        staffName.setText(String.format(staffInfo.getStaffName(), "%8d"));
        staffSexValue.setText(String.format(staffInfo.getStaffSex(), "%8d"));
        staffBrief.setText(String.format(staffInfo.getStaffBrief(), "%8d"));
        staffPosition.setText(String.format(staffInfo.getStaffPosition(), "%8d"));
        staffPhoneValue.setText(String.format(staffInfo.getStaffPhone(), "%8d"));
        if(type== Constants.TYPE_NURSE){

            staffExp.setText("成都中医药大学毕业");
        }else if(type==Constants.TYPE_DOCTOR){
            staffExp.setText("长泰-疑难病特聘专家");
        }
        if(null!=staffInfo.getStaffSex()){
             if("女".equals(staffInfo.getStaffSex())){
                 staffImage.setImageResource(R.drawable.doctor_pic);
             }else if("男".equals(staffInfo.getStaffSex())){
                 staffImage.setImageResource(R.drawable.doctor_man);
             }
        }
        pinYin.setText(ChineseToSpell.getPinYin(staffInfo.getStaffName()).toUpperCase());
    }
    @SuppressLint("ValidFragment")
    public BaseStaffFragment(Long id, int type) {
        this.id = id;
        this.type = type;
    }
}
